package com.bike.bikeserver.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.SysLog;
import com.bike.bikeserver.mapper.SysLogMapper;
import com.bike.bikeserver.service.impl.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.bike.bikeserver.constant.Constants.USER_RIGHT_ALL;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/20 17:45
 */
@RestController
@RequestMapping("sys/sysLog")
public class SysLogController
{
    @Autowired
    SysLogMapper sysLogMapper;
    @Autowired
    SysRoleService sysRoleService;

    /**
     * 获取全部日志信息
     *
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_ALL}, mode = SaMode.OR)
    @GetMapping("getSysLogList")
    public CommonResult getSysLogList()
    {
        List<SysLog> sysLogs = sysLogMapper.selectList(null);
        return CommonResult.success(sysLogs);
    }

    /**
     * 根据数据表名模糊查询
     *
     * @param tName
     * @return
     */
    @GetMapping("getSysLogByTName")
    @SaCheckPermission(value = {USER_RIGHT_ALL}, mode = SaMode.OR)
    public CommonResult getSysLogByTName(@RequestParam("tName") String tName)
    {
        LambdaQueryWrapper<SysLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(SysLog::getTName, tName);
        List<SysLog> sysLogs = sysLogMapper.selectList(wrapper);
        return CommonResult.success("查询成功！为您找到" + sysLogs.size() + "条记录！", sysLogs);
    }
}
